package org.breathe.dynamic.thread.pool.core.reject;

import org.breathe.dynamic.thread.pool.core.notify.alarm.AlarmManager;
import org.breathe.dynamic.thread.pool.core.thread.BreatheDtpExecutor;

import java.util.concurrent.ThreadPoolExecutor;

import static org.breathe.thread.pool.common.enums.NotifyTypeEnum.REJECT;

/**
 * @author: breathe
 * @createTime: 2025-04-09
 */
public interface RejectedAware {
    /**
     * 在拒绝前做一些事情
     */
    default void beforeReject(ThreadPoolExecutor executor) {
        if (executor instanceof BreatheDtpExecutor breatheDtpExecutor) {
            breatheDtpExecutor.incRejectCount(1);
            //报警
            Runnable runnable = () -> AlarmManager.doAlarm(breatheDtpExecutor, REJECT);
            AlarmManager.triggerAlarm(breatheDtpExecutor.getThreadPoolName(), REJECT.getValue(), runnable);
        }
    }
}
